<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>在线留言管理</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="ok-box-center-right">
      <el-form :inline="true" :model="ok_page" class="user-search">
        <el-form-item label="搜索：">
          <el-input size="small" v-model="ok_page.key" placeholder="请输入名字或手机号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table size="small" :data="pagesData.list" highlight-current-row border element-loading-text="拼命加载中" style="width: 100%;">
        <el-table-column prop="realname" label="名字">
        </el-table-column>
        <el-table-column prop="phone" label="手机号" >
        </el-table-column>
        <el-table-column label="时间" >
          <template slot-scope="scope">
            <div>
              {{ok.date.formatDateTime(scope.row.createTime)}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="100">
          <template slot-scope="scope">
            <div v-if="scope.row.checkStatus==0">
              <el-tag type="warning">未查看</el-tag>
            </div>
            <div v-else>
              <el-tag type="success">已查看</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" min-width="100">
          <template slot-scope="scope">
            <div class="ok-box-center">
              <el-button type="success" size="mini" @click="view(scope.row)">查看</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-drawer
          title="留言详情"
          :visible.sync="drawer">
        <div class="ok-box-left" style="margin-left: 40px;display: flex;flex-direction: column">
          <div class="info-div">
            <span class="left-type">名字：</span><span class="right-type">{{info.realname}}</span>
          </div>
          <div class="info-div">
            <span class="left-type">手机号：</span><span class="right-type">{{info.phone}}</span>
          </div>
          <div class="info-div">
            <span class="left-type">状态：</span>
            <span class="right-type" v-if="info.checkStatus==0"><el-tag size="medium" type="warning">未查看</el-tag></span>
            <span class="right-type" v-else><el-tag type="success" size="medium">已查看</el-tag></span>
          </div>
          <div class="info-div">
            <span class="left-type">时间：</span><span class="right-type">{{ok.date.formatDateTime(info.createTime)}}</span>
          </div>
          <div class="info-div">
            <span class="left-type">留言内容：</span><span class="right-type">{{info.message}}</span>
          </div>
        </div>
      </el-drawer>
    </div>
  </div>
</template>
<script>
import ok from "@/assets/ok"
import api from "@/api/manage"
import Cookies from "js-cookie";
export default {
  computed:{
    ok() {
      return ok
    }
  },
  data(){
    return{
      drawer:false,
      info:{},
      ok_page:{
        key:"",
        pageSize:8,
        current:0
      },
      pagesData:{
        list:[],
        pageSize:0,
        current:0,
        total:0
      },
    }
  },
  mounted() {
    this.getPage();
    this.checkLogin();
  },
  methods:{
    checkLogin(){
      if (!ok.tool.getStatus()){
        this.$router.push("/login")
      }
    },
    getPage(){
      api.getFeedbackPage(this.ok_page).then(res =>{
        this.pagesData = res.result;
      });
    },
    view(item){
      this.drawer = true;
      api.getFeedbackInfo({id:item.id}).then(res =>{
        this.info = res.result;
      })
    },
    search(){
      this.getPage();
    }
  }
}
</script>
<style>
.left-type{
  color: #888b8d;
}
.right-type{
  margin-left: 20px;
  font-size: 20px;
}
.info-div{
  width: 100%;
  margin-bottom: 20px;
}
</style>
